package com.akk.utils.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


@ControllerAdvice
public class ExceptionController {

    @ExceptionHandler(value = BusinessException.class)
    @ResponseBody
    public Map exception(BusinessException exception){
//        log.error(exception.getStackTrace());
        Map<String,Object> result = new HashMap<>();
        result.put("code",exception.getCode());
        result.put("message",exception.getMessage());
        return result;
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Map exception(Exception exception){
//        log.error(exception.getStackTrace());
        Map<String,Object> result = new HashMap<>();
        result.put("code","10001");
        result.put("message","系统繁忙");
        result.put("error",exception.getCause());
        result.put("errorMsg",exception.getMessage());
        return result;
    }

}
